package com.hucheng.activity.entity;

import com.hucheng.activity.dto.ExchangeDetailsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-15
 * @Description: 持久层数据
 **/
@Data
public class ExchangeDetailsDO {
    private Integer exchangeDetailsId;
    private Integer userId;
    private Integer exchangeConfigId;
    private Integer exchangeNo;
    private String exchangeName;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;
    private Integer isDel;

    public static ExchangeDetailsDO buildExchangeDO(final ExchangeDetailsDTO exchangeDetailsDTO) {
        if (exchangeDetailsDTO != null) {
            ExchangeDetailsDO exchangeDetailsDO = new ExchangeDetailsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(exchangeDetailsDTO.getExchangeDetailsId()+"")) {
                exchangeDetailsDO.setExchangeConfigId(exchangeDetailsDTO.getExchangeDetailsId());
                exchangeDetailsDO.setDateCreated(currentTime);
            }else{
                exchangeDetailsDO.setDateUpdated(currentTime);
            }
            exchangeDetailsDO.setUserId(exchangeDetailsDTO.getUserId());
            exchangeDetailsDO.setExchangeConfigId(exchangeDetailsDTO.getExchangeConfigId());
            exchangeDetailsDO.setExchangeNo(exchangeDetailsDTO.getExchangeNo());
            exchangeDetailsDO.setExchangeName(exchangeDetailsDTO.getExchangeName());
            exchangeDetailsDO.setIsDel(exchangeDetailsDTO.getIsDel());
            return exchangeDetailsDO;
        }
        return null;
    }
}
